package com.estore;

import java.io.*;
import java.net.*;
import java.util.*;

public class SimpleTest {
    public static void main(String[] args) {
        try {
            System.out.println("=== 测试服务器连接 ===");
            
            // 连接到服务器
            Socket socket = new Socket("localhost", 8888);
            System.out.println("✅ 成功连接到服务器");
            
            // 获取输入输出流
            ObjectOutputStream output = new ObjectOutputStream(socket.getOutputStream());
            ObjectInputStream input = new ObjectInputStream(socket.getInputStream());
            
            // 测试获取商品列表
            System.out.println("测试获取商品列表...");
            output.writeObject("GET ALL PRODUCTS");
            output.flush();
            
            Object response = input.readObject();
            if (response instanceof List) {
                List<?> products = (List<?>) response;
                System.out.println("✅ 成功获取商品列表，共 " + products.size() + " 个商品");
            } else {
                System.out.println("❌ 获取商品列表失败: " + response);
            }
            
            // 测试创建订单
            System.out.println("测试创建订单...");
            String orderRequest = "CREATE ORDER:testUser:p001,1";
            output.writeObject(orderRequest);
            output.flush();
            
            Object orderResponse = input.readObject();
            System.out.println("订单创建响应: " + orderResponse);
            
            socket.close();
            System.out.println("✅ 测试完成");
            
        } catch (Exception e) {
            System.err.println("❌ 测试失败: " + e.getMessage());
            e.printStackTrace();
        }
    }
}